
package at.fhj.itm.metadata.impl.postgres;


import at.fhj.itm.metadata.SqlType;
import at.fhj.itm.metadata.impl.AbstractColumn;

/**
 *
 * @author Seuchter
 */
public class PostgresColumn extends AbstractColumn
        implements Comparable<PostgresColumn>
{

    protected int columnIndex;

    public PostgresColumn(int columnIndex, String name,  boolean isNotNull,  SqlType type, String defaultValue)
    {
        super(name, isNotNull, type, defaultValue);
        setColumnIndex(columnIndex);
    }
    public PostgresColumn(int columnIndex, String name,  boolean isNotNull,  SqlType type, String defaultValue,
    		boolean primaryKeyColumn, boolean foreignKeyColumn)
    {
    	super(name, isNotNull, type, defaultValue,primaryKeyColumn,foreignKeyColumn);
    	setColumnIndex(columnIndex);
    }

    protected void setPrimarKey(boolean pk) {
    	primaryKeyColumn = pk;
	}

    protected void setForeignKey(boolean fk) {
		foreignKeyColumn = fk;
	}

    public void setNotNull(boolean isNotNull)
    {
        this.isNotNull = isNotNull;
    }

    public int getColumnIndex()
    {
        return columnIndex;
    }

    public final void setColumnIndex(int index)
    {
        columnIndex = index;
    }

    public int compareTo(PostgresColumn t)
    {
        return columnIndex - t.getColumnIndex();
    }

    public PostgresColumn copy() {

        return new PostgresColumn(getColumnIndex(), getName(), isNotNull,
                (PostgresSqlDataType) getColumnType(), getDefaultValue());
    }
}
